<%@ page import="java.util.List" %>
<%@ page import="com.bdqn.entity.News" %>

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getServerName() + ":" + request.getServerPort() + path + "/";
    String baseUrlPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
    pageContext.setAttribute("baseUrlPath", baseUrlPath);
%>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/css/common.css">
    <script src="<%=request.getContextPath()%>/static/js/jquery-1.9.1.min.js"></script>
    <style>
        .admin-list > tbody > tr > td {
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .goPointer {
            cursor: pointer;
        }
    </style>
</head>

<body>
<jsp:useBean id="newsService"
             class="com.bdqn.service.Impl.NewsServiceImpl"
></jsp:useBean>
<%
    List<News> newsList = newsService.queryAll();
%>
<!--主体-->
<div class="main-content-right">
    <!--即时新闻-->
    <div class="main-text-box">
        <div class="main-text-box-tbg">
            <div class="main-text-box-bbg">
                <form name="searchForm" id="searchForm"
                      action="#" method="post">
                    <div>
                        新闻分类：
                        <select name="categoryId">
                            <option value="0">全部</option>
                            <option value='1'>国内</option>
                            <option value='2'>国际</option>
                            <option value='3'>娱乐</option>
                            <option value='4'>军事</option>
                            <option value='5'>财经</option>
                            <option value='6'>天气</option>
                        </select>
                        新闻标题<input type="text" name="title" id="title" value=''/>
                        <button type="submit" class="page-btn goPointer">GO</button>
                        <%--完整路径<%=request.getContextPath()%>/jsp/admin/newsDetailCreate.jsp--%>
                        <button type="button" onclick="javaScript:location='newsDetailCreate.jsp'"
                                class="page-btn goPointer">增加
                        </button>
                        <input type="hidden" name="pageIndex" value="1"/>
                    </div>
                </form>
                <table cellpadding="1" cellspacing="1" class="admin-list">
                    <thead>
                    <tr class="admin-list-head">
                        <th>新闻标题</th>
                        <th>作者</th>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <%
                        //用增强型for循环遍历集合
                        int i=0;
                        for(News news:newsList){
                            i++;
                            //隔行变色
                            if(i%2==0){
                     %>
                    <%--如果是偶数行--%>
                    <tr class="admin-list-td-h2">
                    <%
                       }else {
                    %>
                      <tr>
                   <%
                       }
                    %>
                    <tr>
                        <td><%=news.getTitle()%></td>
                        <td><%=news.getAuthor()%></td>
                        <td><%=news.getCreateDate()%></td>
                        <td>
                            <a href="#">修改</a>
                            <a href="javaScript:if(confirm('您确认删除此条新闻吗？')){location='#'}">删除</a>
                        </td>
                    </tr>
                    <%
                        }
                    %>

                    </tbody>
                </table>

            </div>
        </div>
    </div>
</div>
</body>
</html>